package com.lesserpand.rabbitmq.rabbitmq.controller;

import com.lesserpand.rabbitmq.rabbitmq.constant.MqEnum;
import com.lesserpand.rabbitmq.rabbitmq.provider.ProviderUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.UUID;

/**
 * @author pand
 */
@RestController
@RequestMapping("/rq")
public class ProviderController {

    @Autowired
    private ProviderUtils providerUtils;

    @GetMapping("/send")
    public String send(String message) {
        String uuid = UUID.randomUUID().toString();
        // providerUtils.send(uuid, message);
        return uuid;
    }

    @GetMapping("/ttl-send")
    public void ttlSend() {
        // 测试延迟10秒
        providerUtils.sendMessage("测试延迟消费,写入时间：" + new Date(),
                MqEnum.TTL_DIRECT_EXCHANGE.getValue(),
                MqEnum.MESSAGE_TTL_QUEUE_KEY.getValue(),
                10000);
    }

    /**
     * 测试直连发送信息
     */
    @PostMapping(value = "/send-direct-message", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
    public void sendDirectMessage(String message) {
        providerUtils.send(MqEnum.DIRECT_EXCHANGE.getValue(), MqEnum.ROUTINGKEY1.getValue(), message);
    }

}
